package com.globalresources.ui.struts.action.hospital;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.globalresources.po.Hospital;
import com.globalresources.po.City;
import com.globalresources.business.inface.IHospitalService;
import com.globalresources.business.inface.ICityService;
import com.globalresources.commons.AbstractAction;

public class HospitalAction extends AbstractAction implements ServletRequestAware{
	private HttpServletRequest request;
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}		
	private List<Hospital> hospitals;
	private IHospitalService hospitalService;
	private Hospital hospital;
	private List<City> citys;
	private ICityService cityService;
	private String message;
	
	
	public String  listHospital(){		
	    hospitals=hospitalService.listHopistal();
	    return SUCCESS;
	}
	
	public  String saveHospital(){		
		hospitalService.saveHospital(hospital);
		return SUCCESS;
	} 
	
	public String deleteHospital(){		
		String id=request.getParameter("id");
		hospital=hospitalService.getHospitalById(id);
		hospitalService.deleteHospital(hospital);
		setMessage("delete Hospital Success, Please continue your work");
		return SUCCESS;		
	}
	
	public String saveOrUpdateHospital(){
		hospitalService.saveOrUpdateHospital(hospital);
		setMessage("saveOrUpdate Hospital Success, Please continue your work");
		return SUCCESS;
	}
	
	public String editHospital(){
		String id=request.getParameter("id");
		hospital=hospitalService.getHospitalById(id);
		citys=cityService.listCity();
		return SUCCESS;
		
	}	
	
	
	public String addHospital(){
		hospital=null;
		citys=cityService.listCity();
		return SUCCESS;		
	}	


	/**
	 * @return the hospitalService
	 */
	public IHospitalService getHospitalService() {
		return hospitalService;
	}


	/**
	 * @param hospitalService the hospitalService to set
	 */
	public void setHospitalService(IHospitalService hospitalService) {
		this.hospitalService = hospitalService;
	}

	/**
	 * @return the hospitals
	 */
	public List<Hospital> getHospitals() {
		return hospitals;
	}

	/**
	 * @param hospitals the hospitals to set
	 */
	public void setHospitals(List<Hospital> hospitals) {
		this.hospitals = hospitals;
	}

	/**
	 * @return the hospital
	 */
	public Hospital getHospital() {
		return hospital;
	}

	/**
	 * @param hospital the hospital to set
	 */
	public void setHospital(Hospital hospital) {
		this.hospital = hospital;
	}

	/**
	 * @return the citys
	 */
	public List<City> getCitys() {
		return citys;
	}

	/**
	 * @param citys the citys to set
	 */
	public void setCitys(List<City> citys) {
		this.citys = citys;
	}

	/**
	 * @return the cityService
	 */
	public ICityService getCityService() {
		return cityService;
	}

	/**
	 * @param cityService the cityService to set
	 */
	public void setCityService(ICityService cityService) {
		this.cityService = cityService;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	
	
	
	
	
	
	
	
}
